<template>
  <div>
    <div class="placeholder">
      <div class="placeholder-title">风险警告</div>
      <div>1.此操作有风险，如果无特别需求，不建议修改关系链。</div>
      <div>2.修改关系链可能会导致数据不一致。</div>
      <div>3.修改关系链不会立即生效，会根据你的提交任务排队处理。</div>
    </div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入会员ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="phonenumber">
        <el-input
          v-model="queryParams.phonenumber"
          placeholder="请输入会员手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <div style="margin: 10px 0">
      已选：{{ selectUser.length ? selectUser[0].nickName : "" }}
    </div>

    <el-table
      v-loading="loading"
      :data="ruleList"
      @select="handleSelectionChange"
    >
      <el-table-column prop="" label="" width="50" type="selection">
      </el-table-column>
      <el-table-column label="ID" align="center" prop="userId" width="80" />
      <el-table-column label="头像" align="center" prop="avatar">
        <template slot-scope="{ row }">
          <image-preview
            :src="row.avatar"
            width="50px"
            height="50px"
          ></image-preview>
        </template>
      </el-table-column>
      <el-table-column label="昵称" align="center" prop="nickName" />
      <el-table-column label="手机" align="center" prop="phonenumber" />
      <el-table-column label="会员等级" align="center" prop="levelName" />
    </el-table>
  </div>
</template>

<script>
import { getReferrer, putReferrer } from "@/api/system/member/memberDetail";
import { forrmatterEnmu } from "@/utils/index";

export default {
  name: "ChangeRecommender",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户会员表格数据
      ruleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        phonenumber: null,
      },
      selectUser: [],
    };
  },
  created() {
    // this.getList()

    this.queryParams = {
      pageNum: 1,
      pageSize: 10,
      userId: null,
      phonenumber: null,
    };
  },
  methods: {
    forrmatterEnmu,
    /** 查询查询推荐人列表 */
    getList() {
      this.loading = true;
      getReferrer(this.queryParams)
        .then((response) => {
          this.ruleList = response.rows;
          this.loading = false;
        })
        .catch((res) => {
          this.loading = false;
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleSelectionChange(val) {
      this.selectUser = val;
      this.$emit("selectUser", val);
    },
  },
};
</script>
<style lang="less" scoped>
.placeholder {
  background-color: #fef0f0;
  padding: 15px 30px;
  color: #ff4e4e;
  margin-bottom: 15px;
  border-radius: 5px;

  .placeholder-title {
    font-size: 15px;
    font-weight: bold;
    margin-bottom: 10px;
  }
}
</style>
